var UI = {

	// 提示框
	hint : function(obj){

		var icon  = (obj.icon === undefined || obj === undefined) ? 'warm1' : obj.icon;
		var text  = (obj.text === undefined || obj === undefined) ? '未知错误！' : obj.text;
		var html  = '<div class="hintCenter">'+
						'<img class="hint_img" src="./public/image/'+ icon +'.png" alt="" >'+
						'<span>'+ text +'</span>'+
					'</div>'+
				'</div>';

		var body = document.getElementsByTagName('body')[0];

		var element = PARSING.specElement({"element":body.children, "classIndex":"hint_box"});
		var hintBox = document.getElementsByClassName('hint_box');

		if(element[0]){

			body.removeChild(document.getElementsByClassName('hint_box')[0]);
		}

		// 创建元素标签并加入子元素
		let iframe = document.createElement('div');
		iframe.setAttribute('class', 'hint_box');
		iframe.innerHTML = html;

		body.appendChild(iframe);

		// 关闭弹窗模板
		setTimeout(function(){
			if(hintBox[0] != undefined){

				body.removeChild(hintBox[0]);
				if(obj.load != undefined){
					location.reload();
				}
			}
		}, 2000);
	},

	// 确认框
	hintCon : function(obj){
		// 初始化值
		var title = (obj.title === undefined || obj === undefined) ? '系统消息' : obj.title;
		var icon  = (obj.icon === undefined || obj === undefined) ? 'warm' : obj.icon;
		var text  = (obj.text === undefined || obj === undefined) ? '您确定要删删除该条数据吗？' : obj.text;
		var url   = (obj.url === undefined || obj === undefined) ? '' :  obj.url;
		var html  = '<div class="hintCon_title"><span>'+ title +'</span><i class="iconfont" id="shut">X</i></div>'+
					'<div class="middle_box">'+
						'<div class="middle_list"><img src="./public/image/'+ icon +'.png" alt="">'+ text +'</div>'+
						'<p id="btn"><button id="deter">确定</button><button id="cancel">取消</button></p>'+
					'</div>';

		var iframe_box = document.createElement('div'),
			background_box = document.createElement('div');
		// 设置class类名
		background_box.setAttribute('id','backCon');
		iframe_box.setAttribute('class','hintCon');
		iframe_box.innerHTML = html;

		var body = document.getElementsByTagName('body')[0];		

		body.appendChild(iframe_box);
		body.appendChild(background_box);	

		var deter = document.getElementById('deter'),
			shut = document.getElementById('shut'),
			cencel = document.getElementById('cancel');

		// 点击执行事件
		deter.onclick = remove;
		cancel.onclick = remove;
		shut.onclick = remove;

		function remove(){

			body.removeChild(iframe_box);
			body.removeChild(background_box);	

			if(this === deter){
				
				location.href = url;
			}
		}
		return false;
	},

	// 确认框2
	hintDeter : function(obj){
		// 初始化值
		var title = (obj.title === undefined || obj === undefined) ? '系统消息' : obj.title;
		var icon  = (obj.icon === undefined || obj === undefined) ? 'warm' : obj.icon;
		var text  = (obj.text === undefined || obj === undefined) ? '您确定要删删除该条数据吗？' : obj.text;
		var url   = (obj.url === undefined || obj === undefined) ? '' :  obj.url;
		var html  = '<div class="hintCon_title"><span>'+ title +'</span><i class="iconfont" id="shut">X</i></div>'+
					'<div class="middle_box">'+
						'<div class="middle_list"><img src="./public/image/'+ icon +'.png" alt="">'+ text +'</div>'+
						'<p id="btn"><button id="deter">确定</button></p>'+
					'</div>';

		var iframe_box = document.createElement('div'),
			background_box = document.createElement('div');
		// 设置class类名
		background_box.setAttribute('id','backCon');
		iframe_box.setAttribute('class','hintCon');
		iframe_box.innerHTML = html;

		var body = document.getElementsByTagName('body')[0];		

		body.appendChild(iframe_box);
		body.appendChild(background_box);	

		var deter = document.getElementById('deter'),
			shut = document.getElementById('shut');

		// 点击执行事件
		deter.onclick = remove;
		shut.onclick = remove;

		function remove(){

			body.removeChild(iframe_box);
			body.removeChild(background_box);	

			if(this === deter){
				
				location.href = url;
			}
		}
		return false;
	},

	// 模块添加
	moduleList : function(obj){

		var html = (obj === undefined || obj.html === undefined) ? '' : obj.html;
		var tbody  = document.getElementById('myTbody');
		var tr = tbody.getElementsByTagName('tr');

		// 限制模块数量
		if(tr.length === 10){

			this.hint({'text':'模块限制添加10个'});
			return false;
		}

		// 创建tr 元素
		var tr = document.createElement('tr');
		tr.innerHTML = html;

		tbody.appendChild(tr); // 插入HTML元素
	}
}